﻿<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>智运宝TMS</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="css/global.css" media="all">
    <link rel="stylesheet" href="css/index.css" media="all">
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <style>
        .thumb {
            width: 50px;
            height: 50px;
            border-radius: 50%;
        }

    </style>

</head>

<body>
<!--banner上面一条-->
<div class="layui-layout layui-layout-admin">
    <div class="layui-header header header-demo">
        <div class="layui-main">
            <div class="admin-login-box">

                <a class="logo" href="index.html">
                    <img src="../tms/images/logo5.png" style="height: 42px;padding-bottom: 12px"/>
                    <span style="font-size: 25px;color: #ffffff">智运宝</span>
                </a>
                <div class="admin-side-toggle">
                    <i class="fa fa-bars" aria-hidden="true"></i>
                </div>
                <div class="admin-side-full">
                    <i class="fa fa-life-bouy" aria-hidden="true"></i>
                </div>
            </div>
            <ul class="layui-nav admin-header-item">
                <li class="layui-nav-item">

                        <input type="hidden" name="headpic" autocomplete="off" class="layui-input" id="headpic"/>
                        <div class="user-photo"   id="lookheadpicBtn" title=''>
                        </div>

                </li>
                <li class="layui-nav-item">

                    <a href="javascript:;" class="admin-header-user">

                        <span>操作</span>
                    </a>
                    <dl class="layui-nav-child">

                        <dd>
                            <a id="currentUsername"></a>
                        </dd>
                        <dd>
                            <a id="loginOut">注销</a>
                        </dd>
                    </dl>
                </li>
            </ul>
            <ul class="layui-nav admin-header-item-mobile">
                <li class="layui-nav-item">
                    <a href="login.html"><i class="fa fa-sign-out" aria-hidden="true"></i> 注销</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-side layui-bg-blue" id="admin-side">

        <div class="layui-side-scroll" id="admin-navbar-side" lay-filter="side">


        </div>
    </div>
    <div class="layui-body" style="bottom: 0;border-left: solid 2px #0099ff;" id="admin-body">
        <div class="layui-tab admin-nav-card layui-tab-brief" lay-filter="admin-tab">
            <ul class="layui-tab-title">
                <li class="layui-this">
                    <i class="fa fa-home" aria-hidden="true"></i>
                    <cite>主页</cite>
                </li>
            </ul>
            <div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;">
                <div class="layui-tab-item layui-show">
                    <iframe src="main.html"></iframe>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-footer footer footer-demo" id="admin-footer">
        <div class="layui-main">
            <p>Copyright &copy;
                <a href="index.html">杭州长禧智慧物流科技有限公司. All rights reserved.</a>
            </p>
        </div>
    </div>
    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i>
    </div>
    <div class="site-mobile-shade"></div>

    <!--锁屏模板 start-->
    <script type="text/template" id="lock-temp">
        <div class="admin-header-lock" id="lock-box">
            <div class="admin-header-lock-img">
                <img src="images/0.jpg"/>
            </div>
            <div class="admin-header-lock-name" id="lockUserName">beginner</div>
            <input type="text" class="admin-header-lock-input" value="输入密码解锁.." name="lockPwd" id="lockPwd"/>
            <button class="layui-btn layui-btn-small" id="unlock">解锁</button>
        </div>
    </script>
    <!--锁屏模板 end -->
    <script src="./js/config.js"></script>
    <script type="text/javascript" src="plugins/layui/layui.js"></script>
    <script type="text/javascript" src="datas/nav.js"></script>
    <script src="js/index.js"></script>
    <script src="js/tools.js"></script>
    <script src="js/roledata.js"></script>
    <script>
        layui.use(['element', 'upload'], function () {
            var $ = layui.jquery;
            var layer = layui.layer;
            var element = layui.element;
            var upload = layui.upload;
            var yhid = "";

            $.ajax({
                url: contextPath + "/currentUserInfo",
                type: "GET",
                contentType: "application/json;charset=utf-8",
                success: function (res) {
                    console.log(res);
                    $("#headpic").val(res.headpic);
                    //渲染头像
                    divphoto($, layer, "headpic");
                }
            });


            $.ajax({
                url: contextPath + "/currentUser",
                type: "GET",
                contentType: "application/json;charset=utf-8",
                success: function (res) {
                    $("#currentUsername").html('你好' + res.yhm  );

                    yhid = res.yhid;

                    var uploadBtn = $("#lookheadpicBtn");
                    var fileid;
                    upload.render({
                        elem: uploadBtn //绑定元素
                        ,
                        url: contextPath + "/files/?tablename=userinfo&ownerid=" + yhid + "&fileid=" + (fileid = uuid()) //上传接口
                        ,
                        accept: 'file'
                        ,
                        done: function (res) {
                            //上传完毕回调
                            if (res.message == "上传成功") {
                                if ($("#headpic").val() != "") {
                                    console.log(fileid);
                                    $.ajax({
                                        url: contextPath + "/files/" + $("#headpic").val(),
                                        type: "DELETE",
                                        contentType: "application/json;charset=utf-8",
                                        dataType: "json",
                                        success: function (res) {
                                            if (res.message == "删除成功！") {
                                                $("#headpic").val(fileid);
                                                $.ajax({
                                                    url: contextPath + "/headpicup",
                                                    type: "PUT",
                                                    contentType: "application/json;charset=utf-8",
                                                    data: '{"yhid": "' + yhid + '", "headpic": "' + fileid + '"}',
                                                    dataType: "json",
                                                    success: function (res) {
                                                        if (res.message == "上传成功！") {
                                                            layer.msg("上传成功！");
                                                            window.location.reload();
                                                        } else {
                                                            layer.alert(res.message);
                                                        }
                                                    }
                                                });
                                            } else {
                                                layer.alert("上传失败！");
                                            }
                                        }
                                    });

                                } else {
                                    console.log(fileid);
                                    $("#headpic").val(fileid);
                                    $.ajax({
                                        url: contextPath + "/headpicup",
                                        type: "PUT",
                                        contentType: "application/json;charset=utf-8",
                                        data: '{"yhid": "' + yhid + '", "headpic": "' + fileid + '"}',
                                        dataType: "json",
                                        success: function (res) {
                                            if (res.message == "上传成功！") {
                                                layer.msg("上传成功！");
                                                window.location.reload();
                                            } else {
                                                layer.alert(res.message);
                                            }
                                        }
                                    });
                                }


                            }
                        }


                    });
                },
            });

            //
            // function textToImage(name){
            //     // 设置初始值, 防止 name 为空时程序无法执行
            //     var nick = "未知";
            //     // 判断 name 是否为空
            //     if(name){
            //         nick = name.charAt(0);
            //     }
            //     var fontSize = 14;
            //     var fontWeight = 'normal';
            //
            //     var canvas = document.getElementById('canvas');
            //     if(canvas){
            //         canvas.remove();
            //     }else{
            //         var html = "<canvas id='canvas'style='display:none'></canvas>";
            //         $("#headPic").append(html);
            //         canvas = document.getElementById('canvas');
            //     }
            //     canvas.width = 28;
            //     canvas.height = 28;
            //     var context = canvas.getContext('2d');
            //     // 头像背景颜色设置
            //     context.fillStyle = '#2D89EF';
            //     context.fillRect(0, 0, canvas.width, canvas.height);
            //     // 头像字体颜色设置
            //     context.fillStyle = '#FFFFFF';
            //     context.font = fontWeight + ' ' + fontSize + 'px sans-serif';
            //     context.textAlign = 'center';
            //     context.textBaseline="middle";
            //     context.fillText(nick, fontSize, fontSize);
            //     return canvas.toDataURL("image/png");
            // }

            // uploadOneFile(upload,$,layer,"userinfo",yhid,"headpic");

            $("#loginOut").on('click', function () {
                //退出请求
                $.ajax({
                    url: contextPath + "/logoutUser",
                    type: "POST",
                    contentType: "application/json;charset=utf-8",
                    success: function (res) {
                        layer.msg(res.message);
                        window.location.reload();
                    }
                });
            });


        });
    </script>
</div>
</body>

</html>